home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 2.5 KB | 79 lines | [TEXT/CCL2] |
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; btree-dcl.lisp
- ;;
- ;; Copyright © 1992 University of Toronto, Department of Computer Science
- ;; All Rights Reserved
- ;;
- ; author: Mark A. Tapia markt@dgp.toronto.edu or markt@dgp.utoronto.ca
- ;;
- ;; declarations for btrees
- ;;
-
- (in-package btree)
- (provide 'btree-decl)
- (export '(*before* *after* *equal*
- *left* *right* *done*
- *left-taller* *right-taller* *balanced*
- make-btree
- btree-left
- btree-right
- btree-min
- btree-max
- btree-key
- btree-val
- btree-balance
- make-btrail
- btrail-dir
- btrail-node
- btrail-prev))
-
- (defconstant *before* -1 "first key is before second")
- (defconstant *after* 1 "first key is after second")
- (defconstant *equal* 0 "first key equals second")
-
- (defconstant *left* *before* "turn left")
- (defconstant *right* *after* "turn right")
- (defconstant *done* -2 "node already visited")
-
-
- (defconstant *balanced* 0 "tree is balanced")
- (defconstant *left-taller* -1 "left branches are taller")
- (defconstant *right-taller* +1 "right branches are taller")
-
- ;; standard btree structure
- ;; left pointer to the left branch of the rooted subtree
- ;; right pointer to the right branch of the rooted subtree
- ;; key a pointer to the key of the rooted subtree
- ;; val value associated with the key
- ;; min if left then pointer to the leftmost node
- ;; else nil
- ;; min if right then pointer to the right-most node
- ;; else nil
- ;; balance one of *left-taller* *right-taller* *balanced*
- ;; which satistfy *left-taller* + *right-taller* = *balanced* = 0
-
- (defstruct (btree (:type list))
- min left key val right max (balance *balanced*))
-
- ;; a path is a list of any number of btrail structures
- ;; ((dir-1 node-1) ... (dir-n node-n))
- ;; The path indicates the nodes visited (in reverse order) from the root to the first node
- ;; if the node with the key is not found
- ;; dir = nil
- ;; node = key
- ;; prev = direction of the turn from the last node visited on the path
- ;; (btrail-dir node-2)
- ;; otherwise
- ;; dir = one of *equal* *right* *left*
- ;; indicating no turn, or a right or left turn to the previous node
- ;; node = a btree structure
- ;; prev = nil
- ;; The root of the tree is the last node in the list.
-
- (defstruct (btrail (:type list)) dir node prev)
-
-
-
-
-
-